home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / chit / chit_src.lzh / CHIT.ASM next >
Assembly Source File  |  1991-05-23  |  9KB  |  445 lines

  1. ;===============================================================
  2. ;    CHIT ver0.20 for FM-TOWNS (exCHange ITem)        
  3. ;    Copyright(c) 1991 Fuzzball    1991.1/27->1991.5/23    
  4. ;===============================================================
  5.  
  6.         .386p
  7.  
  8. CODE        segment    public dword use32
  9. CODE        ends
  10. DATA        segment    public dword use32
  11. DATA        ends
  12. BSS        segment    public dword use32
  13. BSS        ends
  14. SSEG        segment    stack dword use32
  15. SSEG        ends
  16. DGROUP        group    DATA,BSS
  17.  
  18. KEYIN        macro
  19.         mov    ax,0900h
  20.         int    90h
  21.         endm
  22.  
  23. EGB        macro    no
  24.         mov    ah,no
  25.         call    pword ptr fs:[20h]
  26.         endm
  27.  
  28. EGB_WORK_SIZE    equ    600h
  29. INF_BUF_SIZE    equ    4000h
  30.  
  31. LF        equ    0ah
  32. CR        equ    0dh
  33. ESCAPE        equ    1bh
  34. CSR_R        equ    1ch
  35. CSR_L        equ    1dh
  36. CSR_U        equ    1eh
  37. CSR_D        equ    1fh
  38. SPACE        equ    20h
  39.  
  40. DISP_HOME    equ    0501h
  41. TITLE_SIZE    equ    12
  42. MAX_ITEM    equ    125
  43.  
  44.         extrn    disp_str:near
  45.         extrn    disp_str2:near
  46.         extrn    disp_msg:near
  47. ;===============================================================
  48. CODE        segment
  49.         assume    cs:CODE,ds:DGROUP,ss:SSEG
  50. entry:
  51.         cld
  52.         mov    ax,0110h        ;TBIOS sel
  53.         mov    fs,ax
  54.  
  55.         mov    edi,offset egb_work    ;EGB work
  56.         mov    ecx,EGB_WORK_SIZE
  57.         EGB    00h            ;init EGB
  58.  
  59.         mov    bl,0fh            ;white
  60.         mov    dx,0000h        ;locate0,0
  61.         mov    esi,offset msg_title
  62.         call    disp_str
  63.  
  64.         call    chk_para
  65.         call    inf_read
  66. ;===============================================
  67. ;    main routine start            
  68. ;===============================================
  69. init_start:    call    make_screen
  70.  
  71. main_lp:
  72. ;disp_parameter
  73.         mov    bl,0fh            ;white
  74.         mov    ecx,40h            ;len=40h
  75.         mov    dx,030ah
  76.         movzx    esi,word ptr [now_item]
  77.         shl    esi,7            ;esi=item#*80h
  78.         lea    esi,[esi+inf_buf+40h]    ;offset path+opt
  79.         call    disp_str2        ;disp param
  80.  
  81.         mov    bl,0e0h            ;rev_yellow
  82.         mov    ax,[now_item]
  83.         cmp    ax,[keep_item]
  84.         jne    short set_bar
  85.         mov    bl,0f0h            ;rev_white
  86. set_bar:    call    disp_item        ;chg_atrb
  87.  
  88.         KEYIN
  89.  
  90.         mov    bl,0fh            ;white
  91.         mov    ax,[now_item]
  92.         cmp    ax,[keep_item]
  93.         jne    short reset_bar
  94.         mov    bl,0a0h            ;rev_red
  95. reset_bar:    call    disp_item        ;chg_atrb
  96.  
  97.         mov    al,dl
  98.         mov    edi,offset key_chk_str
  99.         mov    ecx,len_chk_str
  100.         mov    esi,ecx
  101.         repne scasb
  102.         jne    main_lp
  103.         inc    ecx
  104.         sub    esi,ecx
  105.         shl    esi,2
  106.         mov    ax,[now_item]
  107.         jmp    cs:[key_jmp_tbl+esi]
  108.  
  109. key_chk_str    db    SPACE,CSR_R,CSR_L,CSR_U
  110.         db    CSR_D,CR,ESCAPE
  111. len_chk_str    equ    $-key_chk_str
  112.         align    4
  113. key_jmp_tbl    dd    set_keep,mov_right,mov_left,mov_up
  114.         dd    mov_down,save_chk,end_chk
  115. ;===============================================
  116. ;    main routine end            
  117. ;===============================================
  118. ;---------------------------------------------------------------
  119. set_keep:    cmp    ax,[keep_item]
  120.         je    short reset_keep
  121.         cmp    word ptr [keep_item],-1
  122.         je    short keep_ok
  123.         call    exchg_item
  124. reset_keep:    mov    ax,-1
  125. keep_ok:    mov    [keep_item],ax
  126.         jmp    main_lp
  127. ;-----------------------
  128. mov_right:    inc    ax
  129.         cmp    ax,[num_item]
  130.         jne    set_now_item
  131.         xor    ax,ax
  132.         jmp    set_now_item
  133. ;-----------------------
  134. mov_left:    and    ax,ax            ;ax=0?
  135.         jne    short left_ok
  136.         mov    ax,[num_item]
  137. left_ok:    dec    ax
  138.         jmp    set_now_item
  139. ;-----------------------
  140. mov_up:        sub    ax,5
  141.         jge    short set_now_item
  142.         mov    bx,[num_item]
  143.         sub    bx,5
  144. mov_up_lp:    add    ax,5
  145.         cmp    bx,ax
  146.         jg    short mov_up_lp
  147.         jmp    short set_now_item
  148. ;-----------------------
  149. mov_down:    add    ax,5
  150.         cmp    ax,[num_item]
  151.         jl    short set_now_item
  152. mov_down_lp:    sub    ax,5
  153.         cmp    ax,5
  154.         jge    short mov_down_lp
  155.  
  156. set_now_item:    mov    [now_item],ax
  157.         jmp    main_lp
  158. ;-----------------------
  159. save_chk:    mov    esi,offset msg_save?
  160.         call    disp_msg
  161.         call    keyin_yn?
  162.         jb    short not_save        ;[ESC]
  163.         call    inf_save
  164. not_save:    jmp    init_start
  165. ;-----------------------
  166. end_chk:    mov    esi,offset msg_end?
  167.         call    disp_msg
  168.         call    keyin_yn?
  169.         jnb    short main_end
  170.         jmp    init_start
  171.  
  172. main_end:    xor    al,al            ;ret code
  173.  
  174. finish:        push    eax
  175.         mov    edi,offset egb_work
  176.         mov    ecx,EGB_WORK_SIZE
  177.         EGB    00h            ;init EGB
  178.         pop    eax
  179.  
  180.         mov    ah,4ch
  181.         int    21h
  182. ;---------------------------------------------------------------
  183. inf_read    proc    near
  184.  
  185.         mov    ax,3d00h        ;open/read
  186.         mov    edx,offset path
  187.         int    21h            ;ret:ax=handle
  188.         jb    short open_err
  189.         mov    bx,ax            ;handle
  190.  
  191.         mov    edx,offset inf_buf    ;ds:edx=buf adrs
  192.         mov    ecx,MAX_ITEM*80h    ;size
  193.         mov    ah,3fh            ;read
  194.         int    21h            ;ret:ax=read size
  195.  
  196.         shr    ax,7            ;ax=ax/80h=num_item
  197.         mov    [num_item],ax
  198.  
  199.         mov    ah,3eh            ;close
  200.         int    21h
  201.         ret
  202. open_err:
  203.         mov    esi,offset msg_open_err
  204.         call    disp_msg
  205.         KEYIN
  206.  
  207.         mov    al,1            ;ret code
  208.         jmp    finish
  209. inf_read    endp
  210. ;---------------------------------------------------------------
  211. inf_save    proc    near
  212.  
  213.         mov    edx,offset path
  214.         mov    ax,3d01h        ;open/write
  215.         int    21h
  216.         mov    bx,ax            ;handle
  217.  
  218.         mov    edx,offset inf_buf    ;ds:edx=buf adrs
  219.         mov    ax,[num_item]
  220.         shl    ax,7
  221.         movzx    ecx,ax            ;size=num_item*80h
  222.         mov    ah,40h
  223.         int    21h            ;write
  224.         jnb    short file_close
  225.  
  226.         mov    esi,offset msg_save_err
  227.         call    disp_msg
  228.         KEYIN
  229.  
  230. file_close:    mov    ah,3eh
  231.         int    21h            ;close
  232.         ret
  233. inf_save    endp
  234. ;---------------------------------------------------------------
  235. chk_para    proc    near
  236.         push    ds
  237.  
  238.         mov    ax,0004h        ;PSP sel
  239.         mov    ds,ax
  240.  
  241.         mov    esi,80h            ;parameter adrs
  242.         lodsb
  243.         and    al,al
  244.         je    short get_crnt_drv
  245.         movzx    ecx,al            ;ecx=para length
  246.  
  247. chk_para_lp:    lodsb
  248.         cmp    al,SPACE
  249.         jne    short write_drv
  250.         loop    chk_para_lp
  251.  
  252. get_crnt_drv:
  253.         mov    ah,19h            ;get current drv
  254.         int    21h
  255.         add    al,'A'
  256. write_drv:    and    al,0dfh            ;toupper
  257.  
  258.         pop    ds
  259.  
  260.         mov    [path],al
  261.         mov    byte ptr [msg_open_err+6],al
  262.         mov    byte ptr [msg_save?+6],al
  263.  
  264.         ret
  265. chk_para    endp
  266. ;---------------------------------------------------------------
  267. make_screen    proc    near
  268.  
  269.         mov    edi,offset egb_work
  270.         EGB    20h            ;cls
  271.  
  272.         mov    bl,0fh            ;white
  273.         mov    dx,0000h
  274.         mov    esi,offset msg_title
  275.         call    disp_str
  276.         add    dh,2
  277.         mov    esi,offset msg_drive
  278.         call    disp_str
  279.         inc    dh
  280.         mov    esi,offset msg_param
  281.         call    disp_str
  282.  
  283.         movzx    ecx,word ptr [num_item]
  284.         and    ecx,ecx
  285.         je    short disp_item_e
  286.         xor    ax,ax
  287.         mov    bl,0fh            ;white
  288. disp_item_lp:    call    disp_item
  289.         inc    ax
  290.         loop    disp_item_lp
  291. disp_item_e:
  292.         mov    ax,[keep_item]
  293.         cmp    ax,-1
  294.         je    short no_keep_item
  295.         mov    bl,0a0h            ;rev_red
  296.         call    disp_item
  297. no_keep_item:
  298.         ret
  299. make_screen    endp
  300. ;---------------------------------------------------------------
  301. num2loc        proc    near
  302. ;in:    ax=item#
  303. ;out:    dx=locate
  304. ;break:    nothing
  305.         push    eax
  306.  
  307.         mov    dl,5
  308.         div    dl            ;ax/5=al...ah
  309.         xchg    ah,al
  310.         shl    al,4
  311.         mov    dx,ax
  312.         add    dx,DISP_HOME
  313.  
  314.         pop    eax
  315.         ret
  316. num2loc        endp
  317. ;---------------------------------------------------------------
  318. exchg_item    proc    near
  319. ;in:    [now_item],[keep_item]
  320. ;break:    nothing
  321.         pushad
  322.  
  323.         xor    esi,esi
  324.         xor    edi,edi
  325.         mov    si,[now_item]
  326.         mov    di,[keep_item]
  327.         shl    si,7        ;si*=80h
  328.         shl    di,7        ;di*=80h
  329.         mov    eax,offset inf_buf
  330.         add    esi,eax        ;now_item  adrs
  331.         add    edi,eax        ;keep_item adrs
  332.  
  333.         mov    ecx,80h/2    ;=40h word
  334.  
  335. exchg_lp:    mov    ax,[esi]
  336.         xchg    ax,[edi]
  337.         mov    [esi],ax
  338.         add    esi,2
  339.         add    edi,2
  340.         loop    exchg_lp
  341.  
  342.         mov    bl,0fh            ;white
  343.         mov    ax,[now_item]
  344.         call    disp_item
  345.         mov    ax,[keep_item]
  346.         call    disp_item
  347.  
  348.         popad
  349.         ret
  350. exchg_item    endp
  351. ;---------------------------------------------------------------
  352. disp_item    proc    near
  353. ;in:    ax=item#
  354. ;    bl=color
  355. ;break:    nothing
  356.         pushad
  357.  
  358.         call    num2loc            ;dx=locate
  359.  
  360.         movzx    esi,ax
  361.         shl    esi,7
  362.         lea    esi,[esi+inf_buf+33h]    ;offset title
  363.  
  364.         mov    ecx,TITLE_SIZE
  365.         call    disp_str2        ;disp_item
  366.  
  367.         popad
  368.         ret
  369. disp_item    endp
  370. ;---------------------------------------------------------------
  371. keyin_yn?    proc    near
  372. ;in:    nothing
  373. ;out:    CF=0 ... yes=[RETURN]
  374. ;    CF=1 ... no =[ESC]
  375. ;break:    nothing
  376.         push    eax
  377.         push    ebx
  378.         push    edx
  379.  
  380. keyin_yn_lp:    KEYIN
  381.  
  382.         cmp    dl,CR
  383.         je    keyin_CR
  384.         cmp    dl,ESCAPE
  385.         jne    keyin_yn_lp
  386.         stc
  387. keyin_CR:
  388.         pop    edx
  389.         pop    ebx
  390.         pop    eax
  391.         ret
  392. keyin_yn?    endp
  393. ;---------------------------------------------------------------
  394. CODE        ends
  395. ;===============================================================
  396. DATA        segment
  397.  
  398. keep_item    dw    -1
  399.  
  400. msg_title    db    'CHIT ver0.20 for FM-TOWNS'
  401.         db    ' Copyright(c) 1991 Fuzzball',0
  402. msg_param    db    'Parameter=',0
  403. msg_drive    db    'Path='
  404. path        db    'X:\TMENU.INF',0
  405.  
  406. msg_open_err    dw    0a16h,0524h        ;pos_yx,size_yx
  407.         db    '  X:\TMENU.INFが見つかりません。',0
  408.         db    0
  409.         db    '   何かキーを押すと終了します。',0
  410.  
  411. msg_save_err    dw    0c16h,0524h
  412.         db    '     セーブ出来ませんでした。',0
  413.         db    0
  414.         db    '    何かキーを押してください。',0
  415.  
  416. msg_save?    dw    0c16h,0524h
  417.         db    '  X:\TMENU.INFをセーブしますか?',0
  418.         db    0
  419.         db    '      Yes=[RETURN], No=[ESC]',0
  420.  
  421. msg_end?    dw    0c19h,051eh
  422.         db    '    CHITを終了しますか?',0
  423.         db    0
  424.         db    '    Yes=[RET], No=[ESC]',0
  425.  
  426. DATA        ends
  427. ;===============================================================
  428. BSS        segment
  429.  
  430. num_item    dw    ?
  431. now_item    dw    ?
  432.  
  433. egb_work    db    EGB_WORK_SIZE dup(?)    ;egb_work_area
  434. inf_buf        db    INF_BUF_SIZE dup(?)    ;info_buffer
  435.  
  436. BSS        ends
  437. ;===============================================================
  438. SSEG        segment
  439.  
  440.         db    1000h dup(?)        ;stack area
  441.  
  442. SSEG        ends
  443. ;===============================================================
  444.         end    entry
  445.